import { useState, useCallback } from 'react';
import { Toast } from '@douyinfe/semi-ui';
import { IMessageItem } from '@/components/MessageList';

export function useMessageList() {
  const [messageListVisible, setMessageListVisible] = useState(false);
  const [messageList, setMessageList] = useState<Array<IMessageItem>>([]);

  const handleCheckMessageList = useCallback(() => {
    setMessageList([]);
    setMessageListVisible(true);

    try {
      // TODO 先模拟信息列表数据，后面的逻辑待补充
      setMessageList([
        {
          title: '消息标题1',
          content: '消息内容1',
        },
        {
          title: '消息标题2',
          content: '消息内容2',
        },
        {
          title: '消息标题3',
          content: '消息内容3',
        }
      ])
    } catch (e) {
      Toast.error(e instanceof Error ? e.message : '获取消息列表失败');
    }
  }, []);

  const handleCloseMessageList = useCallback(() => {
    setMessageListVisible(false);
    setMessageList([]);
  }, []);

  return {
    messageListVisible,
    messageList,
    handleCheckMessageList,
    handleCloseMessageList,
  };
}
